import 'package:flutter/material.dart';
import 'package:common_utils/common_utils.dart';

class TestCommonUtils {
  static bool initScreen = false;

  static String getCurrentDateTime() {
    return DateUtil.getDateStrByDateTime(DateTime.now());
  }

  static String getCurrentDateTimeZH() {
    return DateUtil.getDateStrByDateTime(DateTime.now(),format: DateFormat.ZH_NORMAL);
  }

  static double getScreenWidth(BuildContext context) {
    _initScreen(context);

    return ScreenUtil.screenWidth;
  }

  static double getScreenHeight(BuildContext context) {
    _initScreen(context);

    return ScreenUtil.screenHeight;
  }

  static double getScreenDensity(BuildContext context) {
    _initScreen(context);

    return ScreenUtil.screenDensity;
  }

  static double getStatusBarHeight(BuildContext context) {
    _initScreen(context);

    return ScreenUtil.statusBarHeight;
  }

  static void _initScreen(BuildContext context) {
    if(!initScreen) {
      ScreenUtil.getInstance().init(context);
      initScreen = true;
    }
  }
}

// //DateUtil example
// String timeNow = DateUtil.getDateStrByDateTime(DateTime.now());//2018-09-16 23:14:56
// String timeNow = DateUtil.getDateStrByDateTime(DateTime.now(),format: DateFormat.ZH_NORMAL);//2018年09月16日 23时16分15秒
// String weekday = DateUtil.getWeekDay(DateTime.parse("2018-09-16"));//Sunday
// String weekdayZh = DateUtil.getZHWeekDay(DateTime.parse("2018-09-16"));//星期日

// //First Page init. Notice!!!
// ScreenUtil.getInstance().init(context);

// ScreenUtil.screenWidth
// ScreenUtil.screenHeight
// ScreenUtil.statusBarHeight
// ScreenUtil.screenDensity

// List listA = ["A", "B", "C"];
// List listB = ["A", "B", "C"];
// print("Two List Is Equal: " + ObjectUtil.twoListIsEqual(listA, listB).toString());

// // Global variable，Reference example
// WidgetUtil widgetUtil = new WidgetUtil();

// @override
// Widget build(BuildContext context) {
//   widgetUtil.asyncPrepare(context, false, (Rect rect) {
//      double width = rect.width;
//      double height = rect.height;
//   });
//     return ;
//  }

// //Widgets must be rendered completely. Otherwise return Rect.zero.
// Rect rect = WidgetUtil.getWidgetBounds(context);
// double width = rect.width;
// double height = rect.height;

// //Widgets must be rendered completely. Otherwise return Offset.zero.
// Offset offset = WidgetUtil.getWidgetLocalToGlobal(context);
// double dx = offset.dx  
// double dx = offset.dy